package com.atguigu.srb.core.controller;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.common.exception.Assert;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.common.result.ResponseEnum;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.Dict;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author LiLi
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/api/core/borrower")
public class BorrowerController {
    @Autowired
    BorrowerService borrowerService;

    @ApiOperation("保存额度申请信息")
    @PostMapping("save")
    public R save(
            @ApiParam("额度申请信息")
            @RequestBody BorrowerVO borrowerVO, HttpServletRequest request){
        String token = request.getHeader("token");
        Assert.notNull(token, ResponseEnum.WEIXIN_FETCH_USERINFO_ERROR);
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerVOByUserId(borrowerVO,userId);
        return R.ok();
    }
}

